import axios from 'axios';
import qs from 'qs';
import config from '../config';
import userEntity from '../entity/user';

const User = {

	/**
	 * 用户登录
	 * @param {object} params 接口请求参数
	 * |-- @param {String} username 用户名
	 * |-- @param {String} password 密码
	 * @returns Promise
	 */
	signIn: (request) => {
		const url = `/${config.version}/user/login`;
		const form = Object.assign({}, config.params, request);
		const requestParam = qs.stringify(form);
		return axios.post(url, requestParam)
			.then(res => userEntity(res));
	},

	/**
	 * 退出登录
	 * @returns Promise
	 */
	signout: () => {
		const url = `/${config.version}/user/logout`;
		return axios.get(url);
	},

};

export default User;
